package com.clkj.xiuzheng.controller.adv;

import com.clkj.xiuzheng.pojo.Shop;
import com.clkj.xiuzheng.pojo.ShopVisit;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.service.ShopService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yawang
 * @create 2024/04/11 10:23:47
 **/
@RestController
@RequestMapping(value = "/shop")
@Api(value = "/shop", tags = {"门店管理"})
@CrossOrigin
public class ShopController {

    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "获取单个区域内信息")
    @PostMapping("/listSHop")
    public Result listSHop(@ApiParam(name = "shopRegion", value = "区域id") @RequestParam("shopRegion") Integer shopRegion){
        try {
            Map  shopList = shopService.shopList(shopRegion);
            return new Result(true, StatusCode.OK,"查询成功",shopList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }

    }

    @ApiOperation(value = "搜索")
    @PostMapping("/searchShop")
    public Result searchShop(@ApiParam(name = "shopRegions", value = "区域id集合") @RequestParam("shopRegions") String shopRegions,
                             @ApiParam(name = "shopTarget", value = "性质集合") @RequestParam("shopTarget") String shopTarget,
                             @ApiParam(name = "shopLevels", value = "消费水平集合") @RequestParam("shopLevels") String shopLevels){
        try {
            Map  shopList = shopService.searchShop(shopRegions,shopTarget,shopLevels);
            return new Result(true, StatusCode.OK,"查询成功",shopList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "后台可视化")
    @PostMapping("/listMain")
    public Result listMain(){
        try {
            Map map = shopService.listMain();
            return new Result(true, StatusCode.OK,"查询成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "合作客户（包括往期和现在）")
    @PostMapping("/listHcustomer")
    public Result listHcustomer(){
        try {
            Map map = shopService.listHcustomer();
            return new Result(true, StatusCode.OK,"查询成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "后台数据统计")
    @PostMapping("/backCount")
    public Result backCount(){
        try {
            Map map = shopService.backCount();
            return new Result(true, StatusCode.OK,"查询成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "工人余额入账记录列表")
    @PostMapping("/MyBalanceList")
    public Result MyBalanceList(@RequestParam(required = false) Integer userId){
        try {
            List<ShopVisit> list = shopService.MyBalanceList(userId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "获取意向单中的广告牌投放信息 0所有未投放广告牌 1 已投放 不传是全部")
    @PostMapping("/getPutList")
    public Result getPutList(@RequestParam Integer pageSize,
                             @RequestParam Integer pageNum,
                             @RequestParam(required = false) Integer isPut){
        try {
            PageInfo list = shopService.getPutList(pageSize,pageNum,isPut);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e){
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

}
